<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>配送关系管理</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>按区域设置配送企业</h1>
        <ol class="breadcrumb">
           <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">配送关系</a></li>
            <li class="active"><a href="#">配送关系设置</a></li>
        </ol>
    </section>
    
		
	<section class="content">
        <div class=" box box-success">
            <div class="box-body">
              <div class="input">   
                    <div class="textalign1">企业名称：</div>
                    <div class="boxinput">
                        <input class="textinput" type="text" id="compName" name="compName" placeholder="企业名称/<spring:message code="message.listForm.pinYinMa"/>"  />
                    </div>
               
                    <!-- <div class="textalign">企业编码：</div>
                    <div class="boxinput">
                        <input class="textinput" type="text" id="compCode" name="compCode" placeholder="企业编码"  />
                    </div> -->
                    
                    <div class="textalign1" >
                		<button    id="selectSee" type="button" onclick="gridSerch();" class="btn btn-success btn-sm">查&nbsp;询</button>
                 	</div>
              </div>			      
			</div>
		</div>
		<div style="margin-top: 5px;"></div>
			<table class="jqgrid" id="gridlist"></table>
		<div style="margin-top: 10px;"></div>
		<div id="prowed2"></div>



<div class=" box box-warning bottongroup" id="bottongroup">
			<label onclick="setDel();" class="btn btn-primary btn-sm">确 定</label>
			<label  onclick="window.location.href='${ctx}/baseGoods/toBaseGoodsDelByArea.html?goodsCode=${param.goodsCode}&projID=${param.projID}&goodsArea=${param.goodsArea}'"   class="btn btn-danger btn-sm" >返 回</label>
		</div>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">

//绑定回车   id="selectSee"
$('#compName,#compCode').bind('keydown', function(event) {
    if (event.keyCode == "13") {
        $('#selectSee').click();
    }
}); 
$("#compName").focus();//加载页面光标在第一个查询框内

function setDel(){
	$("#buttonID").attr("disabled",true);
	  setTimeout( function fun(){$("#buttonID").attr("disabled",false);},2000);
		 var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
			if (rowIds.length <= 0) {
				$.HN.message.alert("请选择要设置配送关系的配送企业！", "消息", "warn");
				return;
			}
			var names="";
			for (var i = 0;i < rowIds.length; i++){
    			var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
        				names += rowdata.compName+"<br/>";
        	}
			$.HN.message.confirm("确定为商品：${form.qualityspecName}设置配送关系吗？", "提示信息", "确定").on(function(e) {
	               if (e) {
			var goodsCode = '${param.goodsCode}';
			var areaCode = '${param.areaId}';
			var list = [];
			for (var i=0; i<rowIds.length; i++) {
				rowId = rowIds[i];
				list.push({"goodsCode":goodsCode,
		    		"areaCode":areaCode,
		    		"delCompCode":rowId});
			}
			$.post("${pageContext.request.contextPath}/baseGoods/setDelByArea.html", {
				"array" : json.jsonToString(list),"areaCode":areaCode,"goodsCode":goodsCode
				}, function(result) {
					if (result.success) {
						$.HN.message.alert("设置成功！", "消息", "success");
						gridSerch();
					} else {
						$.HN.message.alert(result.msg, "消息", "error");
					}
				}, "json")
	               }
	         });
	
	
}
$(document).ready(function (){
	$('.form-inline :input').bind('keydown', function(event) {if (event.keyCode == "13") {search();}}).eq(1).focus();


	jQuery("#gridlist").jqGrid({
		url: "${ctx}/baseGoods/getBaseGoodsDelByAreaList.html?areaId=${param.areaId}&goodsCode=${param.goodsCode}&projID=${param.projID}",
	    mtype: "POST",
		datatype: "json",
		autowidth: true,
		shrinkToFit: true,
	//	height: 285,
	   	colNames:['企业编码','企业名称','组织机构代码','联系人','联系电话'],
	   	colModel:[
	   		{name:'compCode',index:'compCode',width:100,align:"center", sortable:false,hidden:true},
	   		{name:'compName',index:'compName',width:150, sortable:false},
	   		{name:'orgCode',index:'areaId',width:80, align:"left", sortable:false},
	   		{name:'contactName',index:'compRegId',width:80, align:"left", sortable:false},
	   		{name:'compPhone',index:'orgCode',width:60,align:"center", sortable:false}
	   	],
		 rowNum: 20,
	     rowList: [10, 20, 50,100],
	     rownumbers: true,
	     multiselect: true,
	     pager: "#prowed2",
	     viewrecords: true,
	     gridComplete: function(){
          	//序号列宽度自适应（参数为jqgridID）
             autoRNWidth("gridlist");
          	//数据只有一条时默认选中（参数为jqgridID）
              selectByOneData("gridlist");
		     },
	     caption: "${param.goodsCode}/${form.drugCode}/${form.qualityspecName}/${form.formName}/${form.specName}/${form.factor}${form.unit}/${form.materialName}—${areaName}",
	     jsonReader: {
	         repeatitems: false,
	         id: "compCode"
	     }
	   	
	});
	jQuery("#gridlist").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
	$("#gridlist").jqGrid("setGridHeight", create());
	$(window).trigger("resize");
})

function gridSerch(){
	var compCode = $.trim($("#compCode").val());
	var compName = $.trim($("#compName").val());
	$("#gridlist").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"compCode":compCode,
        		"compName":compName,
        		"areaId":"${param.areaId}",
        		"goodsCode":"${param.goodsCode}",
        		"projID":"${param.projID}"},
        		page:1
    }).trigger("reloadGrid"); //重新载入  
}

function gridAreaSerch(){
	var areaCode = $.trim($("#areaCode").val());
	var areaName = $.trim($("#areaName").val());
	$("#list5").jqGrid('setGridParam',{  
        datatype:'json',
        postData:{"areaCode":areaCode,
        		"areaName":areaName}
    }).trigger("reloadGrid"); //重新载入  
}
	    
</script>
</body>
</html>